Skip to content

fix: Import into non-partioned table#90

Merged
RealVidy merged 1 commit intomainfrom
vidy/fix-non-partitioned-tables
Jan 29, 2026
Merged

fix: Import into non-partioned table#90
RealVidy merged 1 commit intomainfrom
vidy/fix-non-partitioned-tables

Conversation

@RealVidy
Copy link
Copy Markdown
Contributor

Fix #82

@revu-bot revu-bot Bot requested a review from revu-bot January 28, 2026 17:57
Copy link
Copy Markdown
Collaborator

@revu-bot revu-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR fixes the critical bug where imports into non-partitioned tables were broken (issue #82). The implementation correctly adds conditional logic to use direct INSERT statements for standard tables while maintaining the stored procedure approach for partitioned tables.

Key Changes

  • ✅ Adds proper branching logic based on DESTINATION_TABLE configuration
  • ✅ Introduces column constants to prevent parameter mis-ordering
  • ✅ Updates test expectations to reflect actual behavior

Issues Found

Severity Issue Impact
CRITICAL SQL injection vulnerability in dynamic table identifier Security risk
IMPORTANT Inconsistent SQL composition pattern Maintainability & potential bugs
MINOR Test comment accuracy Documentation clarity

The core fix is sound, but there's a critical security issue with dynamic table name handling that must be addressed before merging.

Comment thread src/importEvent.ts
Comment on lines +147 to +149
// Direct INSERT for standard (non-partitioned) table
await sql`
INSERT INTO ${sql.id(DESTINATION_TABLE)} (
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[CRITICAL] SQL Injection Vulnerability in Dynamic Table Name

Why this matters:

  • DESTINATION_TABLE comes from environment variables and is used directly in sql.id()
  • If an attacker controls the environment variable, they could inject malicious SQL
  • The sql.id() function is designed for identifiers but doesn't validate the input is a safe table name

Recommended fix:
Validate that DESTINATION_TABLE matches expected table names before using it in SQL:

// At the top of the file or in config validation
const VALID_TABLE_NAMES = [MATOMO_TABLE_NAME, PARTITIONED_MATOMO_TABLE_NAME]

if (!VALID_TABLE_NAMES.includes(DESTINATION_TABLE)) {
  throw new Error(`Invalid DESTINATION_TABLE: ${DESTINATION_TABLE}. Must be one of: ${VALID_TABLE_NAMES.join(', ')}`)
}

Alternatively, use a safer approach by directly referencing the validated constant rather than passing through sql.id().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an attacker has control over our env variables we're in bigger trouble than that anyway

Comment thread src/importEvent.ts Outdated
@RealVidy RealVidy force-pushed the vidy/fix-non-partitioned-tables branch 4 times, most recently from 0c42576 to 9c0fdf1 Compare January 29, 2026 17:02
vidy-br: fix-non-partitioned-tables
@RealVidy RealVidy force-pushed the vidy/fix-non-partitioned-tables branch from 9c0fdf1 to 932db2b Compare January 29, 2026 17:04
@sonarqubecloud
Copy link
Copy Markdown

@RealVidy RealVidy merged commit 0912909 into main Jan 29, 2026
5 checks passed
@RealVidy RealVidy deleted the vidy/fix-non-partitioned-tables branch January 29, 2026 17:13
@tokenbureau
Copy link
Copy Markdown

tokenbureau Bot commented Jan 29, 2026

🎉 This PR is included in version 2.3.14 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@tokenbureau tokenbureau Bot added the released label Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import into standard table (non-partitioned) is broken

3 participants